package sy1;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ServletDemo3", value = "/ServletDemo3")
public class ServletDemo3 extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 取出ServletContext中存的次数
        int count = (Integer)getServletContext().getAttribute("count");
        // 显示到页面
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().println("<h1>网站被刘宇韬访问了 "+count+" 次!</h1>");
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
